<template>
  <!-- 分享内容管理页面 -->
  <div class="wishManage">
      <!-- <el-input style="width:300px;margin-right:1vw;"></el-input>
      <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button> -->
      <el-table class="wishManage_table" :data="shareList.slice((currentPage-1)*pageSize,currentPage*pageSize)" height="620" border>
          <el-table-column prop="name" label="发表用户">
          </el-table-column>
          <el-table-column prop="time" label="发起时间">
          </el-table-column>
          <el-table-column prop="content" label="内容" 
            tooltip-effect="is-light"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="" label="操作">
              <template slot-scope="scope">
                <!-- <i class="el-icon-view information" @click="detailed(userToken,scope.row.id)"></i> -->
                <el-button type="primary" plain @click="passThrough(scope.row.commentId)">审核通过</el-button>
                <el-button type="warning" plain @click="noallow(scope.row.commentId)">不通过</el-button>
                <!-- <i class="el-icon-delete information" @click="del(scope.row.id)"></i> -->
              </template>
          </el-table-column>
      </el-table>
      <div class="paginationBlock">
        <el-pagination  @size-change="handleSizeChange"
         @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize"
         layout="total,prev, pager, next,jumper" :total="total">
        </el-pagination>
      </div>
  </div>
</template>

<script>
// 引入一个中转文件用于调用页面方法
import transfer from '../../../assets/js/transfer.js';
export default {
    data(){
        return{
            shareList:[],//待审核列表
            total:0,
            currentPage: 1,
            pageSize: 6,
        }
    },
    beforeMount(){
        this.getShare()
    },
    mounted(){
        this.getShare()
    },
    methods:{
        getShare(){//获取待审核内容列表
            // console.log("获取到审核内容列表")
            this.axios({
                headers: { Authentication: localStorage.getItem("token") },
                method: "get",
                url: `/comment/getAuditCommentDetailInfoList?pageNum=${this.currentPage}&pageSize=${this.pageSize}`
            }).then(res=>{
                if (res.data.code != 20001) {
                    return this.$message.error(res.data.msg);
                }
                this.shareList = res.data.data.list
                this.total = res.data.data.totals
                // console.log(this.shareList)
                // console.log(res)
            })
        },
        passThrough(commentId){//点击审核通过
            // console.log(commentId)
            this.axios({
                headers: { Authentication: localStorage.getItem("token") },
                method: "PUT",
                url: `/comment/updateShow?commentIds=${commentId}`
            }).then(res=>{
                if (res.data.code != 20001) {
                    return this.$message.error(res.data.msg);
                }
                this.getShare()
                this.$message({
                    message: '已通过审核！',
                    type: 'success'
                });
                transfer.$emit('messageList');
            })
        },
        noallow(commentId){//点击审核不通过
            this.$confirm("确定要删除此条分享吗？",{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(()=>{
                this.axios({
                    headers: { Authentication: localStorage.getItem("token") },
                    method: "DELETE",
                    url: `/comment/delete/${commentId}`
                }).then(res=>{
                    if (res.data.code != 20001) {
                        return this.$message.error(res.data.msg);
                    }
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getShare()
                })
            }).catch(()=>{
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            })
        },
        handleCurrentChange(val){//点击获取页码
            this.currentPage = val
            this.getShare()
            this.currentPage =1
        },
        handleSizeChange(val) {
            this.pageSize = val
            this.currentPage = 1
            // this.userList()
        },
    }
}
</script>

<style lang="scss">
    .wishManage{
        .wishManage_table{
            // margin-top: 2vh;
            .has-gutter{
                th{
                    text-align: center;
                }
            }
            .el-table__body{
                .el-table__row{
                    td{
                        text-align: center;
                    }
                }
            }
        }
        .paginationBlock{
            position: absolute;
            bottom: 5vh;
            left: 0;
            width: 100%;
            .el-pagination{
                // position: absolute;
                // bottom: 14vh;
                // left: 40%;
                text-align: center;
            }
            .el-pager li{
                background: none;
            }
            .btn-next,.btn-prev{
                background: none;
            }
        }
    }
</style>